package com.nema.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sunfiyes 2016年12月19日
 * 用户输入转换
 */
public class UserInput {
	public Map<String, Node> nodeMap = new HashMap<String, Node>();
	
	public Map<String, Node> createNode(Map<String, String> input){
		int index = 0;
		String[] attrib = {"score", "timespan", "duration", "price", "sale_effiency", "country", "language", "education", "certification", "level", "avg_resp_time", "tag"};
		this.nodeMap.put((++index)+"", new Node(index+"", "gig", input.get("gig")));
		this.nodeMap.put((++index)+"", new Node(index+"", "seller", " "));
		for(int i = 0; i < attrib.length; i++){
			if( !input.get(attrib[i]).equals("-1"))
				this.nodeMap.put((++index)+"", new Node(index+"", attrib[i], input.get(attrib[i])));
        }
		return nodeMap;
	}
	
	public Map<String, Map<String, Double>> createNeighborVec(){
		Map<String, Map<String, Double>> neighborVec = new HashMap<String, Map<String, Double>>();
		Map<String, Double> vec;
		for (Map.Entry<String, Node> entry : nodeMap.entrySet()) { 
			String type = entry.getValue().getType();
			if(type.equals("gig")){
				vec = new HashMap<String, Double>(); 
				for (Map.Entry<String, Node> entry_t : nodeMap.entrySet()) { 
					String type_t = entry_t.getValue().getType();
					if(type_t.equals("score") | type_t.equals("timespan") | type_t.equals("duration") | type_t.equals("price") | type_t.equals("seller")) {
						vec.put(entry_t.getKey(), 0.5); 
					}
				}
				neighborVec.put(entry.getKey(), vec);
			}
			if(type.equals("seller")){
				vec = new HashMap<String, Double>(); 
				for (Map.Entry<String, Node> entry_t : nodeMap.entrySet()) { 
					String type_t = entry_t.getValue().getType();
					if(type_t.equals("sale_effiency") | type_t.equals("education") | type_t.equals("certification") | type_t.equals("level") | type_t.equals("country") | type_t.equals("language") | type_t.equals("avg_resp_time")){	
						vec.put(entry_t.getKey(), 0.5); 
					}
				}
				neighborVec.put(entry.getKey(), vec);
			}
			if(type.equals("score") | type.equals("timespan") | type.equals("duration") | type.equals("price") | type.equals("tag") | type.equals("seller")) {
				vec = new HashMap<String, Double>(); 
				vec.put("1", 0.5);
				neighborVec.put(entry.getKey(), vec);
			}
			if(type.equals("sale_effiency") | type.equals("education") | type.equals("certification") | type.equals("level") | type.equals("country") | type.equals("language") | type.equals("avg_resp_time")){	
				vec = new HashMap<String, Double>(); 
				vec.put("2", 0.5);
				neighborVec.put(entry.getKey(), vec);
			}
		}
		return neighborVec;
	}
	
	
	
}





